package me.yricky.mayu.ui.misc

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.loadSvgPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.useResource
import androidx.compose.ui.unit.Density

/**
 * @author Yricky
 * @date 2022/9/29
 */
@Composable
fun svgFont(c:Char,selected:Boolean) = if(selected){
    charBPainterMap[c]
}else {
    charRPainterMap[c]
} ?: emptyPainter

val charRPainterMap = buildMap {
    ('A' .. 'Z').forEach {
        put(it, useResource("svg/r/$it.svg"){i ->
            loadSvgPainter(i, Density(1f,1f))
        })
    }
    put('-',useResource("svg/r/-.svg"){i ->
        loadSvgPainter(i, Density(1f,1f))
    })
}

val charBPainterMap = buildMap {
    ('A' .. 'Z').forEach {
        put(it, useResource("svg/b/$it.svg"){i ->
            loadSvgPainter(i, Density(1f,1f))
        })
    }
    put('-',useResource("svg/b/-.svg"){i ->
        loadSvgPainter(i, Density(1f,1f))
    })
}
val symBolMap = mapOf(
    '|' to useResource("svg/symbol/Match.svg"){i ->
        loadSvgPainter(i, Density(1f,1f))
    },
    'X' to useResource("svg/symbol/MisMatch.svg"){i ->
        loadSvgPainter(i, Density(1f,1f))
    },
)
val emptyPainter = ColorPainter(Color.Transparent)
